<?php

namespace app\common\model;

/**
 * Class ConsultingQuestion
 * @package app\model
 * @property int $id
 * @property int $categoryId
 * @property int $lawyerId
 * @property int $memberId
 * @property string $sourceType
 * @property string $ask
 * @property array $messages
 * @property string $aryStatus
 * @property int $aryTime
 * @property string $aryCode
 * @property string $aryMsg
 * @property string $channel
 * @property int $updated
 * @property int $created
 * @property Member $member
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class ConsultingQuestion extends \app\common\model\BaseModel implements ARYPushInterface
{

    // 数据来源客户端类型 H5 H5打官司落地页 LANDING1落地页1
    const SOURCE_H5 = 'h5';
    const SOURCE_LANDING1 = 'LANDING1';

    // 数据来源业务类型 CONSULTING 咨询 LAWSUIT 打官司  LANDING1落地页1
    const FROM_CONSULTING = 'CONSULTING';
    const FROM_LAWSUIT = 'LAWSUIT';
    const FROM_LANDING1 = 'LANDING1';

    protected $name = 'ConsultingQuestion';

    // 设置json类型字段
    protected $json = ['messages'];
    protected $jsonAssoc = true;

    // 该问题下的全部咨询
    public function consultingArr()
    {
        return $this->hasMany(Consulting::class, 'questionId', 'id');
    }

    public function member()
    {
        return $this->hasOne(Member::class, 'id', 'memberId');
    }

    public function lawyer()
    {
        return $this->hasOne(Member::class, 'id', 'lawyerId');
    }

    public function category()
    {
        return $this->hasOne(LawCaseCategory::class, 'id', 'categoryId');
    }

    public function getCreatedStrAttr($value, $data)
    {
        return humanized_time($data['created'] ?? time());
    }

    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'ConsultingQuestion表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'ConsultingQuestion表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中ConsultingQuestion的键');
    //    }
}
